@extends('admin.admin')

@section('content')
        <!-- Content Header (Page header) -->
<section class="content-header">
    <h1>
        商品管理
        <small>分类列表</small>
        <small>分类品牌</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> 控制面板</a></li>
        <li ><a href="#">商品管理</a></li>
        <li ><a href="/admin/category">分类列表</a></li>
        <li ><a href="/admin/categoryBrand/categoryBrands/{{$cat_id}}">分类品牌</a></li>
    </ol>
</section>

<!-- Main content -->
<section class="content">

    <div class="row">
        <div class="col-xs-12">
            <div class="box box-primary">
                <div class="box-header">
                    <h3 class="box-title">品牌列表</h3>

                    <div class="pull-right">
                        <a href="{{route('admin.categoryBrand.create', $cat_id)}}" type="button" style="display:inline;" class="btn btn-block btn-success btn-xs">
                            <i class="icon  glyphicon glyphicon-plus"></i>
                            添加</a>
                        <a href="{{route('admin.category.index')}}" type="button" style="display:inline;" class="btn btn-block btn-success btn-xs">
                            <i class="icon  glyphicon glyphicon glyphicon-menu-left"></i>
                            返回</a>

                    </div>
                </div>
                <!-- /.box-header -->
                <div class="box-body table-responsive no-padding">
                    <table class="table table-hover">
                        <tr>
                            <th>ID</th>
                            <th style="min-width: 200px;">品牌名称</th>
                            <th style="min-width: 200px;">描述</th>
                            <th>推荐</th>
                            <th style="width: 150px;">操作</th>
                        </tr>
                        <?php //dd($categoryBrands);?>
                        @foreach ($categoryBrands as $brand)
                            <tr>
                                <td>{{$brand->brand_id}}</td>
                                <td>{{$brand->brand_name}}</td>
                                <td>{{$brand->brand_desc}}</td>
                                <td width="9%" class="is_recommend" id="{{$brand->id}}" is_recommend="{{$brand->is_recommend}}">@if($brand->is_recommend==0)
                                        <i  class="glyphicon glyphicon-ok " title="推荐" style=" cursor: pointer;color: green;"></i> <?php //echo ($brand->is_recommend);?>
                                    @else
                                        <i  class="glyphicon glyphicon-remove " title="取消推荐" style=" cursor: pointer;color: red;"></i> <?php //echo ($brand->is_recommend);?>
                                    @endif
                                </td>
                                <td>
                                    <button type="button" class="btn  btn-danger btn-xs" data-toggle="modal"
                                            data-target="#modal{{$brand->brand_id}}"><i
                                                class="icon  glyphicon glyphicon-remove"></i> 删除
                                    </button>

                                    <div id="modal{{$brand->brand_id}}" class="modal fade">
                                        <div class="modal-dialog">
                                            <div class="modal-content">
                                                <div class="modal-header">
                                                    <button type="button" class="close" data-dismiss="modal"
                                                            aria-label="Close"><span aria-hidden="true">&times;</span>
                                                    </button>
                                                    <h4 class="modal-title">删除警告:</h4>
                                                </div>
                                                <div class="modal-body">
                                                    <p>确认要删除品牌[{{$brand->brand_name}}]吗?</p>
                                                </div>
                                                <div class="modal-footer">
                                                    {!! Form::open(['route' => ['admin.categoryBrand.delCategoryBrand', $brand->cat_id, $brand->brand_id],'name'=>$brand->brand_name]) !!}
                                                    {!! Form::hidden('_method', 'DELETE') !!}
                                                    <button type="button" class="btn btn-default" data-dismiss="modal">
                                                        取消
                                                    </button>
                                                    <button type="submit" class="btn btn-danger">删除</button>

                                                    {!!Form::close()   !!}
                                                </div>
                                            </div><!-- /.modal-content -->
                                        </div><!-- /.modal-dialog -->
                                    </div><!-- /.modal -->

                                </td>
                            </tr>
                        @endforeach

                    </table>
                </div>
                <!-- /.box-body -->
            </div>
            <!-- /.box -->
            {!! $categoryBrands->render() !!}
        </div>
    </div>


</section>
<!-- /.content -->
   <script >
        $('.is_recommend').on('click',function(){
            var el = $(this);
            var id = el.attr('id');
            var url = "{{Route('admin.categoryBrand.toggleShow')}}";
            $.ajax({
                url:url+"/?id="+id,
                type:'get',
                dataType:'json',
                success:function(result){
                    if(result.info){
                    //console.log(result.is_recommend);
                        if(result.is_recommend==0){
                            el.find('.glyphicon').removeClass('glyphicon-remove');
                            el.find('.glyphicon').addClass('glyphicon-ok');
                            el.find('.glyphicon').css("color","green");

                        }else{
                         //console.log(result.is_recommend);
                            el.find('.glyphicon').removeClass('glyphicon-ok');
                            el.find('.glyphicon').addClass('glyphicon-remove');
                            el.find('.glyphicon').css("color","red");

                        }

                    }
                }
            });
        });

    </script>
<script>
    $('.btn-danger').on('click', function () {
        console.log('11');
    });
</script>
@endsection